
import API from "./config"
import wepy from "wepy";
export default {
  creatdOrder(data) {
    return API.post(`/order/settle`, data)
  },

  orderCount(page, pageSize) {
    return API.post(`/generalize/orderCount`, { page, pageSize })
  },

  userCount() {
    return API.post(`/generalize/userCount`)
  },

  queryOrder(page, pageSize, orderStatus) {
    return API.post(`/order/list`, { page, pageSize, orderStatus })
  },
  queryStatusOrder(page, pageSize, isPay) {
    return API.post(`/order/payOrderList`, { page, pageSize, isPay })

  },
  buyVirtual(id, buyNum, orderType, mobie) {
    return API.post(`/order/addVirtualOrder`, { id, buyNum, orderType, mobie })
  },

  orderDetail(id) {
    return API.get(`/order/${id}`)
  },

  orderComfirDetail(id) {
    return API.get(`/order/query/${id}`)
  },

  orderUpdate(data) {
    return API.post(`/order/update`, data)
  },

  updateBuyNum(data) {
    return API.post(`/order/updateBuyNum`, data)
  },

  cancelOrder(orderIdList) {
    return API.post(`/order/cancel`, { orderIdList })
  },

  queryExLog(orderId) {
    return API.post(`/order/queryExpInfo`, { orderId })
  },

  async pay(orderId, paySource = 2) {
    let { data } = await API.post(`/order/payment`, { orderId, paySource })
    // console.log(data)
    return await wepy.requestPayment({
      timeStamp: data.timeStamp, //时间戳从1970年1月1日00:00:00至今的秒数,即当前的时间,
      nonceStr: data.nonceStr, //随机字符串，长度为32个字符以下,
      package: data.package, //统一下单接口返回的 prepay_id 参数值，提交格式如：prepay_id=*,
      signType: data.signType, //签名算法，暂支持 MD5,
      paySign: data.paySign, //签名,具体签名方案参见小程序支付接口文档
    });
  },

  comfirOrder(orderIdList) {
    return API.post(`/order/confirm`, { orderIdList })
  }

}
